using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace TermitesMagnets
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Obstacle : Microsoft.Xna.Framework.DrawableGameComponent
    {
        private GameplayScreen game1;
        private Rectangle rect;

        public Rectangle Rect { get { return rect; } set {} }

        private static Texture2D texture;
        private static Texture2D texturewall;
        private static int pixelHeight;
        private static int pixelWidth;
        private Board parent;
        private GameplayScreen GameScreen;

        public Obstacle(Game game, Rectangle rect, Board parent)
            : base(game)
        {
            this.GameScreen = GameplayScreen.GlobalGame;
            this.parent = parent;
            this.game1 = GameplayScreen.GlobalGame;
            this.rect = rect;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            if (GameScreen.IsActive)
            {
                // TODO: Add your update code here
            }
            base.Update(gameTime);
        }

        public static void LoadContent(ContentManager Content)
        {
            Obstacle.texture = Content.Load<Texture2D>(@"Images\termite");
            Obstacle.texturewall = Content.Load<Texture2D>(@"Images\wall");//termite");
            Obstacle.pixelHeight = texture.Height;
            Obstacle.pixelWidth = texture.Width;
        }

        public override void Draw(GameTime gameTime)
        {
            game1.SpriteBatch.Begin(); 
          /*    draw the shape pixle by pixle - ofir chage - the wall texture is \Images\wall.png
            for (int col= rect.Left; col < rect.Right; col++)
            {
                for (int row = rect.Top; row < rect.Bottom; row++)
                {
                    game1.SpriteBatch.Draw(texture, game1.CurrentLevel.Board.WorldPositionToReal(new Vector2(col,row)),  Color.White);//Color.LightPink);
                }
            }*/
            game1.SpriteBatch.Draw(texturewall, new Rectangle(2*rect.Left, 2*rect.Top, 2*(rect.Right - rect.Left), 2*(rect.Bottom - rect.Top)), Color.White);
            game1.SpriteBatch.End(); 
            base.Draw(gameTime);
        }
    }
}
